package com.qf.shop.service.impl;


import com.qf.shop.dao.ProductDao;
import com.qf.shop.dao.impl.ProductDaoImpl;
import com.qf.shop.entity.PageBean;
import com.qf.shop.entity.Product;
import com.qf.shop.service.ProductService;

import java.sql.SQLException;
import java.util.List;

public class ProductServiceImpl implements ProductService{
    ProductDao productDao = new ProductDaoImpl();
    @Override
    public PageBean<Product> findPage(String tid, int page, int pageSize) throws SQLException {

        long count = productDao.selectCountByTid(tid); //查询总条数

        List<Product> list = productDao.selectProductByPage(page,pageSize,tid); //查询当前页对应的商品

        // limit (currentPage-1)*pageSize,pageSize;

        return new PageBean<Product>(list,page,pageSize,count);
    }

    @Override
    public Product findProductByPid(String pid) throws SQLException {

        Product product = productDao.selectProductByPid(pid);

        return product;
    }

    @Override
    public void addProduct(Product product) {

        try {
            productDao.insertProduct(product);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public List<Product> findProductsAll() {
        return productDao.selectAll();
    }
}
